package logic

import (
	"context"
	"errors"
	"strings"
	"video-hub/model/mysql"
	"video-hub/videorpc/internal/svc"
	"video-hub/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ContentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewContentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContentAddLogic {
	return &ContentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ContentAddLogic) ContentAdd(in *videorpc.ContentAddRequest) (*videorpc.ContentAddResponse, error) {
	// todo: add your logic here and delete this line
	content := mysql.Comment{
		VideoId: int(in.VideoId),
		UserId:  int(in.UserId),
		Content: in.Content,
	}
	if strings.Contains(in.Content, "垃圾") || strings.Contains(in.Content, "骗人") {
		return nil, errors.New("含违规词汇，请修改")
	}
	err := content.ContentAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &videorpc.ContentAddResponse{
		ContentId: int64(content.ID),
	}, nil
}
